<template>
    <div class="category">
       <router-link class="search"  tag="div" to="/home/search">
           <div class="ser">
               <span class="icon"></span>
               <span class="desc">商品搜索,共239款好物</span>
           </div>
       </router-link>
       <div class="category_content">
           <div class="left">
                <van-sidebar v-model="active"  @change="onChange">
                    <van-sidebar-item :title="item.name" v-for="item in categoryList" :key="item.id"/>
                </van-sidebar>
           </div>
           <div class="right">
               <div class="banner">
                   <img src="./../../assets/images/category_banner.jpg" alt="">
               </div>
               <div class="title">
                    <span>-</span>
                    <span>{{this.currentOne.name}}分类</span>
                    <span>-</span>
               </div>
               <div class="bottom">
                   <router-link  class="item" v-for="item in subList" :key="item.id" :to="`/category/categorylist?id=${item.id}`" tag="div">
                       <img :src="item.wap_banner_url" alt="">
                       <p>{{item.name}}</p>
                   </router-link>
               </div>
           </div>
       </div>
    </div>
</template>

<script>
import { indexaction,currentaction} from "@/api/category"
export default {
    data() {
        return {
           active: 0,
           categoryList:[],
           currentOne:{},
           subList:[]

        };
    },
    computed: {

    },
    created() {
        indexaction({

        })
        .then(res=>{
            this.categoryList=res.categoryList;
            currentaction({
                id:this.categoryList[0].id
            })
            .then(res=>{
                // console.log(res);
                this.currentOne=res.data.currentOne;
                this.subList=res.data.currentOne.subList;
            })
        });



    },
    mounted() {
        
    },
    methods: {

        onChange(index){
            console.log(index);
            currentaction({
                id:this.categoryList[index].id
            })
            .then(res=>{
                console.log(res);
                this.currentOne=res.data.currentOne;
                this.subList=res.data.currentOne.subList;
            })
        }

       
    },
};
</script>

<style scoped lang="scss">
.search{
    height: 44px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    border-bottom: 1Px solid #ededed;

    .ser{
        width: 345px;
        height: 26px;
        background: #ededed;
        border-radius: 5px;
        display: flex;
        justify-content: center;
        align-items: center;

        .icon{
            width: 14px;
            height: 14px;
            margin-right: 5px;
            background: url('./../../assets/images/search.png') no-repeat;
            background-size: 100%;
            display: block;
        }

        .desc{
            font-size: 12px;
        }
    }
}
.category{
    background-color: #fff;
    height: 100vh;
}
.category_content{
    display: flex;

    .left{
        width: 82px;
    }

    .right{
        width: 263px;
        flex: 1;
        padding: 0 15px;

        .banner{
            width: 100%;
            height: 109px;

            img{
                width: 100%;
                height: 109px;
            }
        }

        .title{
            text-align: center;
            padding: 25px 0;
        }
        .bottom{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            align-items: center;

            .item{
                width: 80px;
                // height: 80px;
                text-align: center;
                margin-bottom: 10px;

                img{
                    display: block;
                    width: 60px;
                    height: 60px;
                    margin: 0 auto;
                }
            }
        }
    }    
}

</style>
